﻿using HZU.ZP.Data.Impl;
using HZU.ZP.Data.Interfaces;
using HZU.ZP.Domain.IService;
using HZU.ZP.Domain.Model;
using HZU.ZP.Domain.ServiceImpl.Mappers;
using System;
using System.Collections.Generic;
using System.Text;

namespace HZU.ZP.Domain.ServiceImpl.PCSvc
{
    public class MessageService:IMessageService
    {
        private MessageMapper _mapper = new MessageMapper();
        private IMessageDao _sqlData;
        public MessageService(IMessageDao sqlData)
        {
            _sqlData = sqlData;
        }

        public bool Add(Message message)
        {
            var messageDao = _mapper.MapToDao(message);
            _sqlData.Add(messageDao);
            return true;
        }

        public Message GetById(int id)
        {
            return _mapper.MapToDomain(_sqlData.GetById(id));
        }

        public IList<Message> GetMesList(string fromEmail, string toEmail)
        {
            return _mapper.MapToDomainList(_sqlData.GetMesList(fromEmail, toEmail));
        }

        public IList<Message> GetMesUserList(string fromEmail, string toId)
        {
            return _mapper.MapToDomainList(_sqlData.GetMesList(fromEmail, toId));
        }

        public bool Update(Message message)
        {
            var messageDao = _mapper.MapToDao(message);
            _sqlData.Update(messageDao);
            return true;
        }

        public bool UpdateList(string sql)
        {
            _sqlData.UpdateList(sql);
            return true;
        }
    }
}
